package nccloud.web.arap.hsbcebankpay.hsbcebankpayvo.action;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;

import org.owasp.esapi.ESAPI;

import nc.bs.pub.service.HsbcPub;
import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.core.io.WebFile;
import nccloud.framework.core.io.WebFileDisposition;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;

public class ExportHsbcEbankPayVOAction implements ICommonAction {

	@Override
	public Object doAction(IRequest request) {
		WebFile downfile = null;
		try {
			Map<String, String[]> webMap = request.readParameters();
			File file = ServiceLocator.find(HsbcPub.class).outPGPFile(webMap);
			downfile = new WebFile(file.getName(), file.length(), new FileInputStream(file));
		} catch (Exception e) {
			e.printStackTrace();
			Object ex = new RuntimeException(e);
			Throwable cause = ExceptionUtils.unmarsh((Throwable) ex);
			String mess = ESAPI.encoder().encodeForHTML(cause.getMessage());
			InputStream in = new ByteArrayInputStream(mess.getBytes());
			downfile = new WebFile("print_error.html", in);
			downfile.setDisposition(WebFileDisposition.Inline);
		}
		return downfile;
	}

}
